﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Data.OleDb;

namespace Web_HengliSeed.BLL
{
    public class WebLink
    {
        /// <summary>
        /// 获取一条链接数据
        /// </summary>
        /// <param name="strClassID"></param>
        /// <returns></returns>
        public static OleDbDataReader GetClassMes(string strClassID)
        {
            try
            {
                OleDbParameter[] parm = { new OleDbParameter("@T_WebLinkID", strClassID) };
                return ClassFile.AccessHelper.ExecuteReader(ClassFile.AccessHelper.ConnectionString, " SELECT * FROM T_WebLink WHERE T_WebLinkID=@T_WebLinkID ", parm);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 获取所有的链接信息
        /// </summary>
        /// <returns></returns>
        public static OleDbDataReader GetClassMes()
        {
            try
            {
                return ClassFile.AccessHelper.ExecuteReader(ClassFile.AccessHelper.ConnectionString, " SELECT * FROM T_WebLink  ", null);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 编辑链接数据（修改）
        /// </summary>
        /// <param name="ClassID"></param>
        /// <param name="strClassName"></param>
        /// <param name="strKey"></param>
        /// <param name="strDes"></param>
        /// <returns></returns>
        public static bool EditClassMes(string ClassID, string strClassName, string strKey, string strDes)
        {
            try
            {
                int classID = Convert.ToInt32(ClassID);
                string strSql = "  UPDATE T_WebLink SET T_WebLinkTitle=@T_WebLinkTitle,T_WebLinkImage=@T_WebLinkImage,T_WebLinkUrl=@T_WebLinkUrl  WHERE T_WebLinkID=@T_WebLinkID ";
                OleDbParameter[] parm = { new OleDbParameter("@T_WebLinkTitle", strClassName),
                                                           new OleDbParameter("@T_WebLinkImage", strKey),
                                                           new OleDbParameter("@T_WebLinkUrl", strDes),
                                                           new OleDbParameter("@T_WebLinkID",classID)};
                return (ClassFile.AccessHelper.ExecuteNonQuery(ClassFile.AccessHelper.ConnectionString, strSql, parm) > 0) ? true : false;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 编辑链接数据（添加）
        /// </summary>
        /// <param name="ClassID"></param>
        /// <param name="strClassName"></param>
        /// <param name="strKey"></param>
        /// <param name="strDes"></param>
        /// <returns></returns>
        public static bool EditClassMes(string strClassName, string strKey, string strDes)
        {
            try
            {
                string strSql = " INSERT INTO  T_WebLink (T_WebLinkTitle,T_WebLinkImage,T_WebLinkUrl) VALUES (@T_WebLinkTitle,@T_WebLinkImage,@T_WebLinkUrl) ";
                OleDbParameter[] parm = { new OleDbParameter("@T_WebLinkTitle", strClassName),
                                          new OleDbParameter("@T_WebLinkImage", strKey),
                                          new OleDbParameter("@T_WebLinkUrl", strDes)};
                return (ClassFile.AccessHelper.ExecuteNonQuery(ClassFile.AccessHelper.ConnectionString, strSql, parm) > 0) ? true : false;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 删除类别信息
        /// </summary>
        /// <param name="strClassID"></param>
        /// <returns></returns>
        public static bool DelClassMes(string strClassID)
        {
            try
            {
                OleDbParameter[] parm = { new OleDbParameter("@T_NewsClassID", strClassID) };
                return (ClassFile.AccessHelper.ExecuteNonQuery(ClassFile.AccessHelper.ConnectionString, " DELETE FROM T_WebLink WHERE T_WebLinkID=@T_WebLinkID ", parm) > 0) ? true : false;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        } 
    }
}
